﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReprojectWebMercator
{
    public class sampler2D
    {
        public Bitmap bitmap { get; set; } = Resource1._20241213093915;

        private Color[,] Colors;
        private int bitmapWidth = 0;
        private int bitmapHeight = 0;

        public int Width
        {
            get
            {
                if(bitmapWidth>0)return bitmapWidth;
                return bitmap.Width;
            }
        }
        public int Height
        {
            get
            {
                if (bitmapHeight > 0) return bitmapHeight;
                return bitmap.Height;
            }
        }

        public void Preload()
        {
            Colors = new Color[bitmap.Width, bitmap.Height];
            for(var i=0;i<bitmap.Width;i++)
            {
                for(var j=0;j<bitmap.Height;j++)
                {
                    Colors[i,j] = bitmap.GetPixel(i,j);
                }
            }
            bitmapWidth= bitmap.Width;
            bitmapHeight= bitmap.Height;
        }

        public Color GetPixel(int i,int j)
        {
            if (Colors != null)
            {
                return Colors[i,j];
            }
            return bitmap.GetPixel(i, j);
        }
    }
}
